home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000134_icon-group-sender_Tue Oct 31 16:32:06 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9VNT7u23929
  4.     for icon-group-addresses; Tue, 31 Oct 2000 16:29:07 -0700 (MST)
  5. Message-Id: <200010312329.e9VNT7u23929@baskerville.CS.Arizona.EDU>
  6. From: Chris.D.Tenaglia@jci.com
  7. Subject: favorites
  8. To: icon-group@cs.arizona.edu
  9. Date: Tue, 31 Oct 2000 16:29:28 -0600
  10. X-MIMETrack: Serialize by Router on jwimkrs1.na.jci.com/NA/Johnson_Controls(Release 5.0.4
  11.  |June 8, 2000) at 10/31/2000 04:37:23 PM
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14. Content-Length: 2361
  15.  
  16. Since this list is getting more active here are some of my favorite
  17. procedures.
  18. The IPL is full of goodies. Some below may be there, but recently I have
  19. been
  20. doing more with the web and CGI, and it's great to build software when you
  21. have
  22. a giant software chip library and are fairly familiar with it.  Just a
  23. couple includes,
  24. a main() and you're done. The procedures below I use extensively, every day
  25. and they sure help.
  26.  
  27. Chris Tenaglia, tech analyst, jci
  28.  
  29.  
  30. #
  31. # parse a string into a list with respect to a delimiter
  32. #
  33. procedure parse(line,delims)
  34.   static chars
  35.   chars  := &cset -- delims
  36.   tokens := []
  37.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  38.   return tokens
  39.   end
  40.  
  41. #
  42. # prompt for an input string
  43. #
  44. procedure input(prompt)
  45.   writes(prompt)
  46.   return read()
  47.   end
  48.  
  49. #
  50. # parse a cgi query string into a table
  51. #
  52. procedure cgiparse(text)
  53.   parts := parse(text,'&')
  54.   lookup:= table("n/a")
  55.   every part := !parts do
  56.     {
  57.     var := parse(part,'=')[1]
  58.     val := map(parse(part,'=')[2],"+"," ") | ""
  59.     lookup[unurl(var)] := map(unurl(val),"\r"," ")
  60.     }
  61.   return lookup
  62.   end
  63.  
  64. #
  65. # error handler if program called wrong
  66. #
  67. procedure error()
  68.   write("content-type: text/html")
  69.   write("")
  70.   write("<HTML>")
  71.   write("<HEAD><TITLE>BAD CALL</TITLE></HEAD>")
  72.   write("<BODY BGCOLOR=80000><font color=#ffffff>")
  73.   write("<PRE><B>\n\n\n")
  74.   write("PROGRAM CALLED INCORRECTLY")
  75.   write("\n\n\n</B></PRE>")
  76.   write("</body>")
  77.   stop("</html>")
  78.   end
  79.  
  80. #
  81. # This procedure maps the wierd characters out of cgi query strings
  82. #
  83. procedure unurl(text)
  84.   static  hex
  85.   initial {
  86.           hex := table("")
  87.           hex["0"] := 0 ; hex["1"] := 1 ; hex["2"] := 2 ; hex["3"] := 3
  88.           hex["4"] := 4 ; hex["5"] := 5 ; hex["6"] := 6 ; hex["7"] := 7
  89.           hex["8"] := 8 ; hex["9"] := 9 ; hex["a"] := 10; hex["A"] := 10
  90.           hex["b"] := 11; hex["B"] := 11; hex["c"] := 12; hex["C"] := 12
  91.           hex["d"] := 13; hex["D"] := 13; hex["e"] := 14; hex["E"] := 14
  92.           hex["f"] := 15; hex["F"] := 15
  93.           }
  94.   work  := map(text,"+"," ")
  95.   cache := []
  96.   every i := 1 to *work do if work[i] == "%" then put(cache,i)
  97.   while i := pull(cache) do
  98.    {
  99.    nyb1 := work[i+1]
  100.    nyb2 := work[i+2]
  101.    if (nyb1 == "") | (nyb2 == "") then next
  102.    raw  := hex[nyb1] * 16 + hex[nyb2]
  103.    byte := char(raw)
  104.    work[i+:3] := byte
  105.    }
  106.   return work
  107.   end
  108.  
  109.  
  110.